#include "sublogin.h"
#include "ui_sublogin.h"
#include "QMessageBox"

SubLogin::SubLogin(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::SubLogin)
{
    ui->setupUi(this);

    m_registerForm = new RegisterForm;
    m_registerForm->hide();

    connect(m_registerForm, SIGNAL(signalUserRegiter(UserInfo)),
            this, SLOT(slotUserRegister(UserInfo)));
    connect(m_registerForm, SIGNAL(signalReturn()),
            this, SLOT(slotReturn()));
}

SubLogin::~SubLogin()
{
    delete ui;
}

void SubLogin::on_pb_login_clicked()
{
    if(ui->le_id->text().isEmpty())
    {
        QMessageBox::warning(this, "警告", "账号不能为空!",
                             QMessageBox::Retry|QMessageBox::Close);
    }else if(ui->le_pswd->text().isEmpty())
    {
        QMessageBox::warning(this, "警告", "密码不能为空!",
                             QMessageBox::Retry|QMessageBox::Close);
    }else
    {
        emit signalUserLogin(ui->le_id->text(), ui->le_pswd->text());
    }
}

void SubLogin::on_pushButton_clicked()
{
    this->hide();
    m_registerForm->show();
}

void SubLogin::slotUserRegister(UserInfo info)
{
    emit signalUserRegiter(info);
}

void SubLogin::registerSuccess()
{
    m_registerForm->hide();
    this->show();
}

void SubLogin::slotReturn()
{
    m_registerForm->hide();
    this->show();
}
